package cn.janus.controller;


import cn.janus.pojo.dto.UserDTO;
import cn.janus.response.Result;
import cn.janus.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author janus
 * @since 2024-07-30
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;

    @PostMapping("/register")
    public Result register(@Validated @RequestBody UserDTO userDTO) {
        userService.saveUser(userDTO);
        return Result.ok();
    }

    @PostMapping("/login")
    public Result login(@Validated @RequestBody UserDTO userDTO) {
        return Result.ok(userService.login(userDTO));
    }

    @GetMapping("/hello")
    public Result Hello() {
//        SecurityContext context = SecurityContextHolder.getContext();
        return Result.ok("hello");
    }

    @GetMapping("/admin")
    public Result admin() {
        return Result.ok("admin");
    }
}
